package unimelb.discussiontracker.twitter.web.converter;

import java.text.SimpleDateFormat;

import unimelb.discussiontracker.twitter.data.entity.TopicIntervalAssociation;
import unimelb.discussiontracker.twitter.web.model.IntervalItem;

public class TopicIntervalAssocToIntervalItemConverter extends AbstractListConverter<TopicIntervalAssociation, IntervalItem> {

    private final String dateFormat;

    public TopicIntervalAssocToIntervalItemConverter(String dateFormat) {
        super();
        this.dateFormat = dateFormat;
    }

    @Override
    public IntervalItem convertItem(TopicIntervalAssociation assoc) {
        final long intervalId = assoc.getInterval().getId();

        final SimpleDateFormat df = new SimpleDateFormat(dateFormat);
        final String start = df.format(assoc.getInterval().getStart());
        final String end = df.format(assoc.getInterval().getEnd());

        final long topicId = assoc.getTopic().getId();
        final int sentiment = assoc.getSentiment();

        return new IntervalItem(intervalId, start, end, topicId, sentiment);
    }
}
